package com.mlnx.bluwifi.tp.youRbp;

public class YouRBpResponse {
    public static byte[] START_OK = new byte[]{(byte) 0xFD,(byte)0xFD,0x05, 0x0D, 0x0A};
    public static byte[] STOP_OK = new byte[]{(byte) 0xFD,(byte)0xFD,0x06, 0x0D, 0x0A};

    /**
     * 和固定返回指令匹配
     *
     * @param compare
     * @return 0 匹配成功指令  1 匹配错误指令  -1 未匹配到指令
     */
    public static int compareByte(byte[] compare) {

//        final StringBuilder stringBuilder = new StringBuilder(compare.length);
//        for (byte byteChar : compare)
//            stringBuilder.append(String.format("%02X ", byteChar));
//        LogUtils.d("内容：" + stringBuilder.toString());

        if (compare.length == START_OK.length) {
            boolean ok = true;
            for (int i = 0; i < compare.length; i++) {
                if (compare[i] != START_OK[i]) {
                    ok = false;
                    break;
                }
            }

            if (ok)
                return 0;
        }
        if (compare.length == STOP_OK.length) {
            boolean ok = true;
            for (int i = 0; i < compare.length; i++) {
                if (compare[i] != STOP_OK[i]) {
                    ok = false;
                    break;
                }
            }

            if (ok)
                return 0;
        }
        return -1;
    }

    public static String getErrorMsg(byte code) {
        switch (code) {
            case (byte) 0x0E:
                return "EEPROM异常";
            case (byte) 0x01:
                return "人体心跳信号太小或压力突降";
            case (byte) 0x02:
                return " 杂讯干扰";
            case (byte) 0x03:
                return "充气时间过长";
            case (byte) 0x04:
                return "测得的结果异常";
            case (byte) 0x0C:
                return "校正异常";
            case (byte) 0x0B:
                return "电源低电压";
            default:
                return "未知错误";

        }
    }
}
